const express = require('express')
const expressJoi = require('@escook/express-joi')
const {
  userLogout,
  userCancellation,
  getUserInfo,
  updateAvatar,
  updatePassword,
  updateUserinfo,
  addAddress,
  updateAddress,
  deleteAddress,
  getAddressList,
  getAddressById,
  AddLike,
  CancelLike,
  getCollection,
  getAllCollectionGoods,
  addCartHandle,
  getAllShopCartGoods,
  getShopCartCount,
  deleteShopCartData,
  editShopCartCount,
  getHistorySearch,
  delSearchHistoryById,
  clearSearchHistory,
  submitOrder,
  getOrderContentByNo,
  getAllOrderByStatus,
  getAllOrders,
  delOrderByOrderIdAndId,
  fromCartAddOrder,
  orderReceipt,
  queryOrderMayResult,
  orderPayment
} = require('../router_handler/user.js')
const {
  user_update_avatar,
  user_update_password_schema,
  update_userinfo_schema,
  add_address_schema,
  update_address_schema,
  add_cancel_like_schema,
  get_goods_collection_schema,
  get_all_collection_schema,
  add_cart_schema,
  del_shopCart_schema,
  edit_cart_goods_count,
  del_search_history_schema,
  submit_order_schema,
  get_order_id_schema,
  get_order_status_schema,
  get_all_order_schema,
  del_order_schema,
  submit_cart_order_schema,
  query_pay_result_schema,
  payment_schema
} = require('../schema/userSchema')
// 创建用户路由对象
const router = express.Router()

//#region
// 用户退出登录
router.post('/logout', userLogout)

// 用户注销账号
router.post('/cancellation', userCancellation)

// 获取用户信息
router.get('/userinfo', getUserInfo)

// 上传用户头像
router.post('/update/avatar', expressJoi(user_update_avatar), updateAvatar)

// 用户修改密码
router.post('/update/password', expressJoi(user_update_password_schema), updatePassword)

// 完善用户信息
router.post('/update/userinfo', expressJoi(update_userinfo_schema), updateUserinfo)

// 添加收货地址
router.post('/add/address', expressJoi(add_address_schema), addAddress)

// 修改收货地址
router.post('/update/address/:id', expressJoi(update_address_schema), updateAddress)

// 删除收货地址
router.post('/del/address/:id', deleteAddress)

// 获取收货地址列表
router.get('/address/list', getAddressList)

// 根据id获取收货地址信息
router.get('/address/:id', getAddressById)

//用户收藏商品
router.post('/add/like', expressJoi(add_cancel_like_schema), AddLike)

// 用户取消收藏商品
router.post('/cancel/like', expressJoi(add_cancel_like_schema), CancelLike)

// 根据商品id获取收藏信息
router.get('/goods/collection', expressJoi(get_goods_collection_schema), getCollection)

// 获取所有商品收藏信息
router.get('/all/collection', expressJoi(get_all_collection_schema), getAllCollectionGoods)

// 添加购物车
router.post('/add/cart', expressJoi(add_cart_schema), addCartHandle)

// 获取购物车商品列表
router.get('/all/cart/goods', getAllShopCartGoods)

// 获取购物车数量
router.get('/cart/count', getShopCartCount)

// 删除购物车
router.post('/del/cart/goods', expressJoi(del_shopCart_schema), deleteShopCartData)

// 修改购物车商品数量
router.post('/edit/cart/goods/count', expressJoi(edit_cart_goods_count), editShopCartCount)

//#endregion

// 获取搜索历史
router.get('/history/search', getHistorySearch)

// 删除一条搜索历史
router.post('/del/search/history', expressJoi(del_search_history_schema), delSearchHistoryById)

// 清空搜索历史记录
router.post('/clear/search/history', clearSearchHistory)

// 提交订单
router.post('/submit/order', expressJoi(submit_order_schema), submitOrder)

// 从购物车提交订单
router.post('/cart/add/order', expressJoi(submit_cart_order_schema), fromCartAddOrder)

// 根据id获取订详情
router.get('/get/order/:id', expressJoi(get_order_id_schema), getOrderContentByNo)

// 根据状态获取订单
router.get('/get/orders/status', expressJoi(get_order_status_schema), getAllOrderByStatus)

// 获取订单列表
router.get('/get/all/order', expressJoi(get_all_order_schema), getAllOrders)

// 订单收货
router.post('/order/receipt', expressJoi(del_order_schema), orderReceipt)

// 删除订单
router.post('/del/order', expressJoi(del_order_schema), delOrderByOrderIdAndId)

// 支付订单
router.post('/payment', expressJoi(payment_schema), orderPayment)

// 查询订单支付结果
router.get('/order/payment/result', expressJoi(query_pay_result_schema), queryOrderMayResult)

module.exports = router
